package code.example.base.collection.queue.blockingqueue;

import com.google.common.base.Objects;

import java.util.Date;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class TimerGift  implements Delayed{

    Date date = null;
    String gift = null;

    public TimerGift(Date date,String gift){
        this.date = date;
        this.gift = gift;
    }
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getGift() {
        return gift;
    }

    public void setGift(String gift) {
        this.gift = gift;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return date.getTime() - System.currentTimeMillis();
    }

    public int compare(Date date ){
        if(this.date == null){
            return 1;
        }else if(date == null){
            return -1;
        }else {
            return this.date.compareTo(date);
        }
    }
    @Override
    public int compareTo(Delayed o) {
        if(o == null || !TimerGift.class.isInstance(o)){
            return -1;
        }else{
            TimerGift timerGift = (TimerGift)o;
            return compare(timerGift.getDate());
        }

    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this)
                .add("date", date)
                .add("gift", gift)
                .toString();
    }
}
